﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmallDataBase.DTO;

namespace SmallDataBase
{
    /// <summary>
    /// 将数据库数据类型转换成.net数据类型
    /// </summary>
    public sealed class TypeChange
    {
        /// <summary>
        /// 将不同数据库数据类型转换成.net数据类型
        /// </summary>
        /// <param name="source"></param>
        /// <param name="type">数据库数据类型</param>
        /// <returns>转变类型后的数据</returns>
        public static Object Convert(object source,DataBaseType type)
        {
            switch (type)
            {
                case DataBaseType.MySQL:
                    return MySQLChange(source);
                case DataBaseType.SQLServer2000:
                    //TODO:类型转换
                    return null;
            }
            return source;
        }

        private static Object MySQLChange(object source)
        {
            if (source is MySql.Data.Types.MySqlDateTime)
            {
                return DateTime.Parse(source.ToString());
            }
            return source;
        }
    }
}
